class Solution(object):
    def countBattleships(self, board):
        """
        :type board: List[List[str]]
        :rtype: int
        """
        m = len(board)
        n = len(board[0])
        total = 0
        for i in range(m):
            for j in range(n):
                if board[i][j] == 'X':
                    c = 0
                    for ux, uy in [(i - 1, j), (i + 1, j), (i, j - 1), (i, j + 1)]:
                        if 0 <= ux < m and 0 <= uy < n:
                            if board[ux][uy] != 'X':
                                c += 1
                        else:
                            c += 1
                    if c == 4:
                        total += 1
                    if c == 3:
                        total += 0.5
        return int(total)